package com.YOUtils.Base.Str;

import com.YOUtils.Base.Characher.YoCharUtils;
import com.YOUtils.YException.YNullPointerException;

/**
 * Created on 2023/6/13
 *
 * @Time 20:36
 * @Program YOUilt
 * @Author YoHaNe/XiaoShuai
 */
public class YoStringUtils {

    public static boolean isEmpty(String str){
        if(str == null || str.length() <= 0)
            return true;
        int r = 0;
        for(int i=0;i<str.length();i++){
            if(YoCharUtils.isEmpty(str.charAt(i)))
                r++;
        }
        return r == str.length();
    }

    public static boolean isEmpty(String[] array){
        if(array == null || array.length <= 0)
            return true;
        int r = 0;
        for(String str : array){
            if(isEmpty(str))
                r++;
        }
        return r == array.length;
    }

    public static String merge(char... chars){
        if(chars == null || chars.length <= 0)
            throw new NullPointerException();
        return new String(chars);
    }

    public static int count(String str,char mate){
        return YoCharUtils.count(str.toCharArray(),mate);
    }

    public static String toLow(String str){
        if(isEmpty(str))
            throw new YNullPointerException();
        int l = str.length();
        char[] chars = new char[l];
        for(int i=0;i<l;i++){
            chars[i] = YoCharUtils.toLow(str.charAt(i));
        }
        return new String(chars);
    }

    public static String toUp(String str){
        if(isEmpty(str))
            throw new YNullPointerException();
        int l = str.length();
        char[] chars = new char[l];
        for(int i=0;i<l;i++){
            chars[i] = YoCharUtils.toUp(str.charAt(i));
        }
        return new String(chars);
    }

    public static int hasChinese(String str){
        if(isEmpty(str))
            return 0;
        int r = 0;
        for(char c : str.toCharArray()){
            if(YoCharUtils.isChinese(c))
                r++;
        }
        return r;
    }

    public static boolean isAllChinese(String str){
        return str.length() == hasChinese(str);
    }



}
